/*  1:   */ package nl.siegmann.epublib.viewer;
/*  2:   */ 
/*  3:   */ import javax.swing.JSlider;
/*  4:   */ import javax.swing.event.ChangeEvent;
/*  5:   */ import javax.swing.event.ChangeListener;
/*  6:   */ import nl.siegmann.epublib.browsersupport.NavigationEvent;
/*  7:   */ import nl.siegmann.epublib.browsersupport.NavigationEventListener;
/*  8:   */ import nl.siegmann.epublib.browsersupport.Navigator;
/*  9:   */ import nl.siegmann.epublib.domain.Book;
/* 10:   */ import nl.siegmann.epublib.domain.Spine;
/* 11:   */ 
/* 12:   */ class SpineSlider
/* 13:   */   extends JSlider
/* 14:   */   implements NavigationEventListener
/* 15:   */ {
/* 16:   */   private static final long serialVersionUID = 8436441824668551056L;
/* 17:   */   private final Navigator navigator;
/* 18:   */   
/* 19:   */   public SpineSlider(Navigator navigator)
/* 20:   */   {
/* 21:22 */     super(0);
/* 22:23 */     this.navigator = navigator;
/* 23:24 */     navigator.addNavigationEventListener(this);
/* 24:25 */     setPaintLabels(false);
/* 25:26 */     addChangeListener(new ChangeListener()
/* 26:   */     {
/* 27:   */       public void stateChanged(ChangeEvent evt)
/* 28:   */       {
/* 29:28 */         JSlider slider = (JSlider)evt.getSource();
/* 30:29 */         int value = slider.getValue();
/* 31:30 */         SpineSlider.this.navigator.gotoSpineSection(value, SpineSlider.this);
/* 32:   */       }
/* 33:32 */     });
/* 34:33 */     initBook(navigator.getBook());
/* 35:   */   }
/* 36:   */   
/* 37:   */   private void initBook(Book book)
/* 38:   */   {
/* 39:37 */     if (book == null) {
/* 40:38 */       return;
/* 41:   */     }
/* 42:40 */     super.setMinimum(0);
/* 43:41 */     super.setMaximum(book.getSpine().size() - 1);
/* 44:42 */     super.setValue(0);
/* 45:   */     
/* 46:44 */     updateToolTip();
/* 47:   */   }
/* 48:   */   
/* 49:   */   private void updateToolTip()
/* 50:   */   {
/* 51:48 */     String tooltip = "";
/* 52:49 */     if ((this.navigator.getCurrentSpinePos() >= 0) && (this.navigator.getBook() != null)) {
/* 53:50 */       tooltip = String.valueOf(this.navigator.getCurrentSpinePos() + 1) + " / " + this.navigator.getBook().getSpine().size();
/* 54:   */     }
/* 55:52 */     setToolTipText(tooltip);
/* 56:   */   }
/* 57:   */   
/* 58:   */   public void navigationPerformed(NavigationEvent navigationEvent)
/* 59:   */   {
/* 60:57 */     updateToolTip();
/* 61:58 */     if (this == navigationEvent.getSource()) {
/* 62:59 */       return;
/* 63:   */     }
/* 64:62 */     if (navigationEvent.isBookChanged()) {
/* 65:63 */       initBook(navigationEvent.getCurrentBook());
/* 66:64 */     } else if (navigationEvent.isResourceChanged()) {
/* 67:65 */       setValue(navigationEvent.getCurrentSpinePos());
/* 68:   */     }
/* 69:   */   }
/* 70:   */ }


/* Location:           C:\Users\David\workspace\CosaRaraPorqueSi\main\epublib-tools-3.1.jar
 * Qualified Name:     nl.siegmann.epublib.viewer.SpineSlider
 * JD-Core Version:    0.7.0.1
 */